package communication.client.vertx.config;

import communication.common.business.base.EventBusManager;
import communication.common.business.base.FcrAutoConfig;
import communication.common.business.heartbeat.HeartBeatServiceOfClient;
import communication.common.command.NetCli;
import communication.common.command.VertxCommand;
import communication.common.shell.FcrServerShell;
import communication.common.business.base.HandleMsgData;
import communication.common.vertx.net.NetManager;
import io.vertx.core.Vertx;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author mac
 */

@Configuration
public class FcrClientBeanConfig {

    @Autowired
    private ApplicationContext applicationContext;

    @Autowired
    private FcrAutoConfig fcrAutoConfig;


    @Bean
    HandleMsgData handleMsgData(){
        return new HandleMsgData(applicationContext);
    }


    @Bean
    FcrServerShell fcrServerShell(){
        return new FcrServerShell();
    }

    @Bean
    EventBusManager eventBusManager(){
        return new EventBusManager();
    }

    @Bean
    Vertx vertx(){
        return Vertx.vertx();
    }

    @Bean
    NetManager netManager(){
        return new NetManager(handleMsgData(),vertx());
    }

    @Bean
    VertxCommand vertxCommand(){
        return new VertxCommand();
    }

    @Bean
    HeartBeatServiceOfClient heartBeatServiceOfClient() throws Exception {
        return new HeartBeatServiceOfClient(netManager(),fcrAutoConfig);
    }


    @Bean
    NetCli netCli(){
        return new NetCli(fcrAutoConfig,netManager());
    }

}
